<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\api\controller;

use app\api\validate\PaymentValidate;
use app\common\logic\PaymentLogic;
use app\common\service\FileService;

/**
 * 支付/转账控制器
 * Class PaymentController
 * @package app\api\controller
 */
class PaymentController extends BaseApiController
{
    /**
     * @notes 创建打款记录
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 10:00
     */
    public function create()
    {
        $params = (new PaymentValidate())->post()->goCheck('create');
        $params['user_id'] = $this->userId;
        $params['group_id'] = $this->userInfo['group_id'];

        $result = PaymentLogic::create($params);
        if (true === $result) {
            return $this->success('创建成功', [], 1, 1);
        }
        return $this->fail(PaymentLogic::getError());
    }
    
    /**
     * @notes 获取打款记录列表
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 10:10
     */
    public function lists()
    {
        $params = $this->request->get();
        $params['group_id'] = $this->userInfo['group_id'];
        $result = PaymentLogic::lists($params);
        return $this->data($result);
    }
    
    /**
     * @notes 获取打款记录详情
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 10:20
     */
    public function detail()
    {
        $params = (new PaymentValidate())->goCheck('detail');
        $params['user_id'] = $this->userId;
        $result = PaymentLogic::detail($params);
        return $this->data($result);
    }
    
    /**
     * @notes 更新打款记录状态
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 10:30
     */
    public function updateStatus()
    {
        $params = (new PaymentValidate())->post()->goCheck('updateStatus');
        $params['user_id'] = $this->userId;
        $result = PaymentLogic::updateStatus($params);
        if (true === $result) {
            return $this->success('状态更新成功', [], 1, 1);
        }
        return $this->fail(PaymentLogic::getError());
    }
    
    /**
     * @notes 删除打款记录
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 10:40
     */
    public function delete()
    {
        $params = (new PaymentValidate())->post()->goCheck('delete');
        $params['user_id'] = $this->userId;
        $result = PaymentLogic::delete($params);
        if (true === $result) {
            return $this->success('删除成功', [], 1, 1);
        }
        return $this->fail(PaymentLogic::getError());
    }
    
    /**
     * @notes 上传打款凭证
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 10:50
     */
    public function uploadProof()
    {
        $params = (new PaymentValidate())->post()->goCheck('uploadProof');
        $params['user_id'] = $this->userId;
        $result = PaymentLogic::uploadProof($params);
        if (true === $result) {
            return $this->success('上传成功', [], 1, 1);
        }
        return $this->fail(PaymentLogic::getError());
    }
    
    /**
     * @notes 获取支付统计信息
     * @return \think\response\Json
     * @author dev
     * @date 2024/03/31 11:00
     */
    public function statistics()
    {
        $params = $this->request->get();
        $params['user_id'] = $this->userId;
        $result = PaymentLogic::statistics($params);
        return $this->data($result);
    }
}